package com.example.luke.cashorderingsystem.Model;


import android.content.Context;

import com.example.luke.cashorderingsystem.Database.DingHanDB;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

/**
 * Created by luke on 11/20/16.
 */

public class PurchaseReport {
    public static   final String DH_TABLE_NAME = "PurchaseReport";
    public static   final String  item_ticketID="ticketID";
    public static   final String  item_commodityID="commodityID";
    public static   final String  item_commodityName="commodityName";
    public static   final String  item_volume="volume";
    public static   final String  item_primeCost="primeCost";
    public static   final String  item_saleCost="saleCost";
    public static   final String  item_cost="cost";

    public static   final String  item_restoredNum="restoredNum";
    public static   final String  item_discount="discount";
    public static   final String  item_dateTime="dateTime";
    public static   final String  item_dateTimeCopy="dateTimeCopy";
    public static   final String  item_employeeID="employeeID";

    //    0 - 现金
//    1-信用卡
//    2 -签单
//    3 - 会员卡
//    4 - 礼劵
//    8 - 退货  会员卡
//    9 - 退货  现金
//    12 - 积分换货
    public static   final String  item_payMode="payMode";
    public  static  final String item_uploadMark="uploadMark";


//    public static   final String  item_position="item_position";//商品编号
//    public static   final String  item_pinyinID="item_pinyinID";//商品名称
//    public static  final String  item_id="item_id";//数量
//
//    public static  final String  item_discountable="tem_discountable";
//
//    public static  final String  item_unit="item_unit";
//    public static  final String  item_storedNumber="item_storedNumber";
//    public static  final String  item_priceIn="item_priceIn";//0 现金,1 信用卡,2 签单,3 会员卡,4 礼劵, 8 - 退货  会员卡,9 - 退货  现金
//    public static  final String item_name="item_name";
//    public static  final String item_barcode="item_barcode";//进货价
//    public  static final String item_priceout="item_priceout";//会员价
//    public static  final String item_warning="item_warning";
//    public static  final String item_kind="item_kind";


    public  static final String DH_CREATE_TABLE="CREATE TABLE " + DH_TABLE_NAME + "( "+item_ticketID+" TEXT," + item_commodityID + " TEXT," + item_commodityName+" TEXT,"+ item_volume + " INTEGER,"
            + item_primeCost + " TEXT," + item_saleCost + " TEXT," + item_cost + " TEXT,"    + item_restoredNum + " INTEGER, "
            + item_discount + " TEXT," +item_dateTime+" TEXT,"+item_dateTimeCopy+" TEXT,"+ item_employeeID + " TEXT," + item_payMode + " INTEGER," + item_uploadMark +" INTEGER"+  ")";

    private String ticketID;

     private String commodityID;
    private String commodityName;

    private Integer volume;
    private  String primeCost;

    private  String saleCost;
    private  String cost;
    private   Integer restoredNum;
    private  String disCount;
    private String dateTime;
    private String dateTimeCopy;
    private String employeeID;
    private  Integer payMode;
    private Integer uploadMark=0;
    private String date;

    public static void insertReport(Context context,PurchaseReport report){
        DingHanDB.getInstance(context).insert(DH_TABLE_NAME,report);

    }

    public static void changeReportUploadMark(Context context,PurchaseReport report){

        report.setUploadMark(1);
        DingHanDB.getInstance(context).changeReportUploadMark(report);

    }
    public static ArrayList<PurchaseReport>getPurchaseReportOnTypeAndInterval( Context context,String startDate,String endDate) throws java.text.ParseException{
        ArrayList<PurchaseReport> allReport=PurchaseReport.getPurchaseReport(context);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd", Locale.getDefault());
        Date tempStartDate=sdf.parse(startDate);

        Date tempEndDate=sdf.parse(endDate);

        ArrayList<PurchaseReport>temp=new ArrayList<>();

        for (PurchaseReport report:allReport){
            String[]dateTemp=report.getDateTime().split(" ");

            Date date=sdf.parse(dateTemp[0]);

            if (tempStartDate.compareTo(date)==0 || tempStartDate.compareTo(date)<0){

                if (tempEndDate.compareTo(date)==0 || date.compareTo(tempEndDate)<0){

                    temp.add(report);

                }


            }
        }

        return temp;


    }
    public static ArrayList<PurchaseReport>getPurchaseReport(Context context){
        return DingHanDB.getInstance(context).getPurchaseReport();

    }
    public String getTicketID() {
        return ticketID;
    }

    public String getCommodityID() {
        return commodityID;
    }

    public String getCommodityName() {
        return commodityName;
    }

    public Integer getVolume() {
        return volume;
    }

    public String getDisCount() {
        return disCount;
    }

    public String getPrimeCost() {
        return primeCost;
    }

    public String getSaleCost() {
        return saleCost;
    }


    public String getCost() {
        return cost;
    }

    public Integer getRestoredNum() {
        return restoredNum;
    }

    public String getDateTime() {
        return dateTime;
    }

    public String getDateTimeCopy() {
        return dateTimeCopy;
    }

    public String getEmployeeID() {
        return employeeID;
    }

    public String getDate() {
        return date;
    }

    public Integer getPayMode() {
        return payMode;
    }

    public Integer getUploadMark() {
        return uploadMark;
    }

    public void setTicketID(String ticketID) {
        this.ticketID = ticketID;
    }

    public void setCommodityName(String commodityName) {
        this.commodityName = commodityName;
    }

    public void setCommodityID(String commodityID) {
        this.commodityID = commodityID;
    }

    public void setVolume(Integer volume) {
        this.volume = volume;
    }

    public void setPrimeCost(String primeCost) {
        this.primeCost = primeCost;
    }

    public void setSaleCost(String saleCost) {
        this.saleCost = saleCost;
    }

    public void setCost(String cost) {
        this.cost = cost;
    }

    public void setRestoredNum(Integer restoredNum) {
        this.restoredNum = restoredNum;
    }

    public void setDisCount(String disCount) {
        this.disCount = disCount;
    }

    public void setDateTime(String dateTime) {
        this.dateTime = dateTime;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public void setDateTimeCopy(String dateTimeCopy) {
        this.dateTimeCopy = dateTimeCopy;
    }

    public void setEmployeeID(String employeeID) {
        this.employeeID = employeeID;
    }

    public void setPayMode(Integer payMode) {
        this.payMode = payMode;
    }

    public void setUploadMark(Integer uploadMark) {
        this.uploadMark = uploadMark;
    }


}
